﻿using System;
using System.Windows;
using System.Windows.Controls;
using jSLApp.Client.MainService;
using jSLCore.Client.Presentation.BaseControl;
using jSLCore.Client.Presentation.BaseControl.Selection;

namespace jSLApp.Client.Forms
{
    public partial class BrowseSource : DialogControl
    {
        private readonly string _oldValue;

        public BrowseSource(string oldValue):this()
        {
            _oldValue = oldValue;
        }

        public BrowseSource()
        {
            InitializeComponent();
        }

        private void browse_Clicked(object sender, RoutedEventArgs e)
        {
            var dlg = new FileList(){SelectionMode=GridSelectionMode.SingleRow};

            dlg.ShowDialog(delegate(object o, object data)
                               {
                                   var fileEntry = (FileEntry)data;
                                   txt.Value = fileEntry.Name;
                                   Validate();
                 
                               });
        }

        #region dialog
        
        public override void OkClicked()
        {
            InvokeDataSelected(txt.Value);
        }

        public override bool IsOkVisible
        {
            get { return true; }
        }

        public override bool IsStandartOkCancelEnabled
        {
            get { return true; }
        }

        public override bool AutoSize
        {
            get { return true; }
        }

        public override void LoadInitialData()
        {
            txt.Value = _oldValue;
        }

        public override Control GetControlForInitialFocus()
        {
            return txt;
        }

        #endregion
    }
}
